<script>

export default {
  name: "Header",
  data() {
    return {
      userInfo: {
        id: "",
        username: "",
        avatar: ""
      }
    }
  },
  created() {
    this.getUserInfo()
  }
  ,
  methods: {
    getUserInfo() {
      this.userInfo = this.$cookies.get('userInfo')
    }
    ,
    handleLogout() {
      localStorage.clear()
      sessionStorage.clear()
      this.$store.commit("resetState")
      this.$router.push("/login")
    }
  }
}
</script>

<template>
  <div class="header">
    <router-link to="/"><strong style="float: left;size: 1000px;font-size: 25px">
      校园综合服务管理平台</strong></router-link>
    <div class="header-avatar">
      <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>
      <el-dropdown style="color: aliceblue">
						<span class="el-dropdown-link">
						{{ userInfo.username }}<i class="el-icon-arrow-down el-icon--right"></i>
						</span>
        <el-dropdown-menu v-slot="dropdown">
          <el-dropdown-item>
            <router-link :to="{name: 'UserCenter'}">个人中心</router-link>
          </el-dropdown-item>
          <el-dropdown-item @click.native="handleLogout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<style scoped>
.header-avatar {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-dropdown-link {
  cursor: pointer;
}

a {
  text-decoration: none;
}
</style>